package com.bw.medical.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.medical.entity.HospitalEntity;
import com.bw.medical.service.HospitalService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 医院表 
 *
 * @author wj
 * @email sunlightcs@gmail.com
 * @date 2021-08-22 21:39:10
 */
@RestController
@RequestMapping("medical/tbhospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    /**
     * 医院列表展示
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        String hospitalName="";
        if (!params.get("hospitalName").toString().equals("")){
            hospitalName=params.get("hospitalName").toString();
        }
        PageUtils page = hospitalService.queryPage(params,hospitalName);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{hospitalId}")
    public R info(@PathVariable("hospitalId") Integer hospitalId){
		HospitalEntity hospital = hospitalService.getById(hospitalId);

        return R.ok().put("hospital", hospital);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HospitalEntity hospital){
		hospitalService.save(hospital);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HospitalEntity hospital){
		hospitalService.updateById(hospital);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] hospitalIds){
		hospitalService.removeByIds(Arrays.asList(hospitalIds));

        return R.ok();
    }

}
